{use master_page('admin/v_master')}  

{block content}

<?php $ci = &get_instance(); 
function bl_class($children,$level=1)
{
	$ci = & get_instance();
	foreach($children as $child)
	{
		$title = $child->title;
		$pad = "";
		if($level>1)
		{
			for($i=0;$i<$level-1;$i++)
			{
				$pad = $pad . "&nbsp;&nbsp;";
			}
			$pad = $pad."└";
		}
		if($level == 1){
			$pad="";
		}
		// $title = str_pad($title,'-',strlen($title)+level,STR_PAD_LEFT);

		echo "<option value='".$child->id."'>$pad$title</option>" ;
		if(sizeof($child->children)>0)
		{
			bl_class($child->children,$level+1);
		}
	}
}
?>


<link href="../../scripts/kindeditor/themes/default/default.css" rel="stylesheet" type="text/css"></link>
<script>
// alert('abc') ; 
KindEditor.ready(function(K) {
	var editor = K.editor({
		allowFileManager : true
	});  
	K('#upload_image').click(function() { 
		editor.loadPlugin('image', function() {
			editor.plugin.imageDialog({
				imageUrl : K('#image').val(),
				clickFn : function(url, title, width, height, border, align) {
					K('#image').val(url);
					editor.hideDialog();
					$('#img_container').attr('src',url) ;
				}
			});


			$('.ke-dialog-row').css('display','none');
			$('.ke-dialog-row:first').css('display',''); 
		});
	});
});
</script>
<div class="line"> 
<form action="<?=$_SERVER['REQUEST_URI']?>" method="post"> 
	<div class="blank20" style="height:20px"></div>
	<div id="tagscontent" class="right_box">
		<table class="formtable" style="border:0px solid #cfcfcf;width:100%">
			<tr class='form_line' >
				<td class='title' style="text-align:right;width:15%"><?=lang('link_title')?></td>
				<td class='content'>
					<input name='p_title' size='48' value='<?=set_value('p_title', $title)?>' type='text' />  
					<?=form_error('p_title', '<font color="red">', '</font>')?>  
				</td>
			</tr>
			<tr class='form_line'> 
				<td class='title' style="text-align:right;"><?=lang('link_url')?></td>
				<td class='content'>
					<input name='p_url' size='48' value='<?=set_value('p_url', $url)?>' type='text' />  
					<?=form_error('p_url', '<font color="red">', '</font>')?>  
				</td>
			</tr> 
			<tr class='form_line'>
				<td class='title' style="text-align:right;"><?=lang('link_image')?></td>
				<td class='content'>
					<?php if(!empty($image)):?>
					<img src="{image}" id="img_container" style="border:1px solid #aaaaaa"></img><br/> 
					<?php endif?>
					<input name='p_image' readonly='readonly' id="image" size='48' value='<?=set_value('p_image', $image)?>' type='text' />
					<input type="button" class="btn_upload" id="upload_image" value=" 上传图片 "/>  
					<?=form_error('p_image', '<font color="red">', '</font>')?>  
				</td>
			</tr> 
			<tr class='form_line' >
				<td class='title' style="text-align:right;"><?=lang('link_profile')?></td> 
				<td class='content'>
					<textarea name='p_profile' id='content' style="height:250px"><?=set_value('p_profile', $profile)?></textarea>  
					<?=form_error('p_profile', '<font color="red">', '</font>')?>   
				</td>
			</tr>  
			<?$cls = $this->link_class_manager->get($this->input->get('class_id'));?>
			<?$children = 
				!empty($_GET['class_id'])?$cls->children:$this->link_class_manager->get_root_list();?>
			<?if(sizeof($children)>0):?>
			<tr class='form_line'> 
				<td class='title'><?=lang('link_class')?></td>
				<td class='content'>
					<select id = 'class_id' class='bind'>
						<option value="">请选择</option>
						<?php if(!empty($_GET['class_id'])):?>
						<option value='{cls->id}'>{cls->title}</option>  
						<?php endif;?>
						<?php bl_class($children,1)?>
					</select>  
					<input name='p_class_id' value='<?=set_value('p_class_id', $class_id)?>' type='hidden' />   
					<?=form_error('p_class_id', '<font color="red">', '</font>')?>    
				</td>
			</tr>
			<?else:?>
			<input name='p_class_id' value='<?=set_value('p_class_id', $class_id)?>' type='hidden' /> 
			<?endif;?>
			
		</table> 
		</div>
		<div class="blank20"style="height:20px"></div>
		<input type="submit" name="submit" value=" 提交 " class="btn_a">
</form>
</div> 
{end} 